package gatperdut.chato.core.keywords;

import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONArray;

public class KeywordsController {

    private final List<String> keywords;

    public KeywordsController( List<String> keywords ) {
        this.keywords = keywords;
    }

    public boolean matchesKeyword( String someKeyword ) {
        for ( String keyword : getKeywords() ) {
            if ( keyword.equals( someKeyword ) ) {
                return true;
            }
        }

        return false;
    }

    @SuppressWarnings( "unchecked" )
    public static JSONArray toJSONArray( List<String> keywords ) {
        JSONArray keywordsJSONArray = new JSONArray();
        for ( String keyword : keywords ) {
            keywordsJSONArray.add( keyword );
        }
        return keywordsJSONArray;
    }

    public static List<String> toStringsList( JSONArray keywords ) {
        List<String> stringsList = new ArrayList<String>();

        for ( int i = 0; i < keywords.size(); i++ ) {
            stringsList.add( (String) keywords.get( i ) );
        }

        return stringsList;
    }

    public List<String> getKeywords() {
        return keywords;
    }
}
